<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function Common(name,age,sex) {
      console.log(this);
      this.name = name;
      this.age = age;
      this.sex = sex;
    }
    // 父类原型中有一个方法需要继承
    Common.prototype.sayh = function () {
      console.log(1);
    }
    function Student(name,age,sex,aihao) {
      // 直接对父类构造函数进行一个普通的调用
        // Common普通调用的时候指向的是window
        // 通过call方法改变指向
        console.log(this);
      Common.call(this,name,age,sex);
      // Common.call(Student,name,age,sex);
      this.aihao = aihao;
    }
    function Teacher(fangx) {
      this.fangx = fangx;
    }


    // 原型继承方法1
    Student.prototype  = Common.prototype;
    Student.prototype.constructor = Student;

      //方法2object create()创建一个对象，使用现有的对象作为新创建对象的原型
      Student.prototype = Object.create(Common.prototype) ;
      Student.prototype.constructor = Student;

    // 创建学生实例
    var s1 = new Student("xs",17,"man","reader");
    var s2 = new Student("x121s",127,"ma22n","rea22der");
    s1.sayh()
    console.log(s1);
    console.log(s2);
  </script>
</body>
</html>